﻿#include "mythread.h"
#include "clog.h"

MyThread::MyThread(QTcpSocket *sock)
{
    if(sock == nullptr)
    {
        CLog::getInstance()->writeLog("[MyThread::MyThread]=>sock is null.\n");
        qDebug() << "[MyThread::MyThread]=>sock is null.\n";
    }
    m_psock = sock;
}

void MyThread::onConnecting(QString type)
{
    if(type == "file")
    {
        connect(m_psock,&QTcpSocket::readyRead,this,&MyThread::handleFileRecv);
    }
    else if(type == "img")
    {
        connect(m_psock,&QTcpSocket::readyRead,this,&MyThread::handleImgRecv);
    }
    else if(type == "audio")
    {
        connect(m_psock,&QTcpSocket::readyRead,this,&MyThread::handleAudioRecv);
    }
    else if(type == "video")
    {
        connect(m_psock,&QTcpSocket::readyRead,this,&MyThread::handleVideoRecv);
    }
    connect(m_psock,&QTcpSocket::stateChanged,this,&MyThread::OnSocketStatus);
}

void MyThread::handleFileRecv()
{

}

void MyThread::handleImgRecv()
{

}

void MyThread::handleAudioRecv()
{

}

void MyThread::handleVideoRecv()
{

}

void MyThread::OnSocketStatus(QAbstractSocket::SocketState socketState)
{
    switch (socketState) {
    case QAbstractSocket::ConnectedState://已连接
        break;
    case QAbstractSocket::ClosingState://断开连接
        break;
    default:
        break;
    }
}
